package models

import (
	"time"
)

type User struct {
	ID        uint   `gorm:"primaryKey"`
	Phone     string `gorm:"unique;size:15;not null"` // 添加手机号唯一约束
	Password  string `gorm:"size:128;not null"`
	Nickname  string `gorm:"size:50;not null"`
	CreatedAt time.Time
}

// Friend 好友关系模型
type Friend struct {
	ID        uint      `gorm:"primaryKey"`
	UserID    uint      `gorm:"index"` // 用户ID
	FriendID  uint      `gorm:"index"` // 好友ID
	CreatedAt time.Time // 成为好友的时间
}

// FriendRequest 好友请求模型
type FriendRequest struct {
	ID          uint   `gorm:"primaryKey"`
	RequesterID uint   `gorm:"index"`            // 请求者ID
	RequesteeID uint   `gorm:"index"`            // 被请求者ID
	Status      string `gorm:"type:varchar(20)"` // pending, accepted, rejected
	CreatedAt   time.Time
	RespondedAt time.Time // 响应时间
}

// 好友请求状态常量
const (
	RequestStatusPending  = "pending"
	RequestStatusAccepted = "accepted"
	RequestStatusRejected = "rejected"
)

// Message 消息模型
type Message struct {
	ID          uint        `gorm:"primaryKey" json:"id"`
	SenderID    uint        `gorm:"index" json:"sender_id"`
	RecipientID uint        `gorm:"index" json:"recipient_id"` // 私聊时有效
	GroupID     uint        `gorm:"index" json:"group_id"`     // 群聊时有效
	Content     string      `gorm:"text;not null" json:"content"`
	MessageType MessageType `gorm:"type:varchar(20);not null" json:"message_type"`
	CreatedAt   time.Time   `gorm:"autoCreateTime" json:"created_at"`
	IsRecalled  bool        `gorm:"default:false" json:"is_recalled"`
}

// MessageType 消息类型
type MessageType string

const (
	MessageTypePrivate MessageType = "private"
	MessageTypeGroup   MessageType = "group"
)

// Group 群组模型
type Group struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"varchar(100);not null" json:"name"`
	CreatorID uint      `gorm:"index;not null" json:"creator_id"`
	CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}

// GroupMember 群成员模型
type GroupMember struct {
	ID       uint      `gorm:"primaryKey" json:"id"`
	GroupID  uint      `gorm:"index;not null" json:"group_id"`
	UserID   uint      `gorm:"index;not null" json:"user_id"`
	JoinedAt time.Time `gorm:"autoCreateTime" json:"joined_at"`
}
